package com.wonders.hisdoctor.station.project.medicine.controller;

import com.wonders.his.common.bean.BaseResult;
import com.wonders.hisdoctor.station.project.medicine.enums.LevelEnum;
import com.wonders.hisdoctor.station.project.medicine.service.ICipherPrescSerive;
import com.wonders.hisdoctor.station.project.medicine.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 张澎_9970
 * @date 2021.2.20 下午 3:07 星期六
 * @desc: 协定处方_Controller
 */
@Api(tags = "门诊用药")
@RestController
@RequestMapping("/cipher")
public class CipherPrescController {

    @Autowired
    private ICipherPrescSerive cipherPrescSerive;

    /**
     * 协定处方_另存
     */
    @ApiOperation("协定处方_另存")
    @PostMapping("saveAs")
    public BaseResult<Integer> saveAs(@RequestBody CiperPrescVo ciperPrescVo) {
        return BaseResult.success(cipherPrescSerive.saveAs(ciperPrescVo));
    }

    /**
     * 协定处方_新版_查询_上列表
     */
    @ApiOperation("协定处方_查询_上列表_新版")
    @PostMapping("qryCipherPresc")
    public BaseResult<List<OutpCipherPrescVo>> qryCipherPresc(@RequestBody QryCipherPrescVO qryCipherPrescVO) {
        if (LevelEnum.HOSPITAL.getCode().equals(qryCipherPrescVO.getCipherType())) {
            qryCipherPrescVO.setOwner("");
            qryCipherPrescVO.setDeptCode("");
        }
        if (LevelEnum.DEPARTMENT.getCode().equals(qryCipherPrescVO.getCipherType())) {
            qryCipherPrescVO.setOwner("");
        }
        List<OutpCipherPrescVo> outpCipherPrescs = cipherPrescSerive.qryCipherPresc(qryCipherPrescVO);
        return BaseResult.success(outpCipherPrescs);
    }

    /**
     * 协定处方_查询_下列表
     */
    @ApiOperation("协定处方_查询_下列表")
    @GetMapping("queryCipherPrescDetail")
    public BaseResult<List<CipherPrescDetailVO>> queryCipherPrescDetail(String cipherId) {
        return BaseResult.success(cipherPrescSerive.queryCipherPrescDetail(cipherId));
    }

    /**
     * 转方_校验
     */
    @ApiOperation("转方_校验")
    @PostMapping("cipherCheck")
    public BaseResult<CipherQuoteVO> cipherCheck(@RequestBody List<CipherPrescDetailVO> list, @RequestParam String patientId) {
        return BaseResult.success(cipherPrescSerive.cipherCheck(list, patientId));
    }

    /**
     * 协定处方_删除
     */
    @ApiOperation("协定处方_删除")
    @DeleteMapping("delete")
    public BaseResult<Integer> delete(String cipherId, String empNo) {
        Integer num = cipherPrescSerive.delete(cipherId, empNo);
        return BaseResult.success(num);
    }

}
